@extends('layouts.app')
@include('personnel.sidebar')
@section('content')
    <div class="content">
        <div class="row custom-invoice">
            <div class="">
                <form id="select-form" class="form form-inline" method="{{ route('admin.personnel.index') }}" action="">
                    <div class="form-group">
                        <input class="form-control" type="text" name="search" id="" value="{{ $search }}" placeholder="电话/姓名">
                    </div>
                    <div class="form-group">
                        <input class="form-control" type="text" name="searchShop" id="" value="{{ $searchShop }}" placeholder="商家">
                    </div>
                    <button type="submit" class="btn btn-success" value="">搜索</button>
                    
                    @can("personnel_export")
                        <button type="submit" class="btn btn-primary" name="export" value="1">导出</button>
                    @endcan
                </form>
            </div>
            <br />
            @can('personnel-add')
                <a class="btn btn-success" href="{{ route("admin.personnel.create") }}">添加工作人员</a>
            @endcan
            <br/>
            <br/>
            <table class="table table-striped table-hover">
                <thead>
                <tr>
                    <th style="min-width:100px">姓名</th>
                    <th style="min-width:100px">账号</th>
                    {{--                    <th>头像</th>--}}
                    {{--                    <th>是否是店员</th>--}}
                    <th style="min-width:100px">是否已禁用</th>
                    {{--                    <th>简介</th>--}}
                    <th style="min-width:100px">所属商户</th>
                    <th style="min-width:200px">权限组</th>
                    <th style="min-width:400px">操作</th>
                    <th style="min-width:200px">排序权重</th>
                </tr>
                </thead>
                <tbody>
                @foreach($data as $item)
                    <tr>
                        <td>{{ $item->name }}</td>
                        <td>{{ $item->username }}</td>
                        {{--                        <td>--}}
                        {{--                            <img src="{{ empty($item->avatar)? "" : \App\Library\OSS::instance()->getUrl($item->avatar) }}" width="30">--}}
                        {{--                        </td>--}}
                        {{--                        <td>{!! $item->is_clerk? "<i class='fa  fa-check'></i>":"" !!}</td>--}}
                        <td>{!! $item->is_disabled? "<i class='fa  fa-check'></i>":""  !!}</td>
                        {{--                        <th>{{ $item->description }}</th>--}}
                        <td>
                            @if(!empty($item->shop_id))
                                @php
                                    $shopName = "";
                                    if (!empty($item->shop_id)) {
                                        $item->shop_id  = json_decode($item->shop_id,true);
                                        foreach ($item->shop_id as $value) {
                                            $shop = $allShops->get($value);
                                            if (!is_null($shop)) {
                                                $shopName .= $shop->name."<br />";
                                            }
                                        }
                                    }
                                @endphp
                                {!! $shopName !!}
                            @endif
                        </td>
                        <td>{{ $item->role }}</td>
                        <td>
                            @can('personnel-edit')
                                <a class="btn btn-primary btn-xs"
                                   href="{{ route('admin.personnel.edit', ['id' => $item->id]) }}"><i
                                        class="fa fa-edit"></i> 编辑</a>
                            @endcan
                            @can('personnel-enable-disable')
                                @if($item->is_disabled)
                                    <a class="btn btn-primary btn-xs"
                                       href="{{ route('admin.personnel.disable', ['id' => $item->id]) }}"><i
                                            class="fa fa-circle-o-notch"></i> 解禁</a>
                                @else
                                    <a class="btn btn-primary btn-xs"
                                       href="{{ route('admin.personnel.disable', ['id' => $item->id]) }}"><i
                                            class="fa fa-ban"></i> 禁用</a>
                                @endif
                            @endcan

                            @can('personnel_resetpwd')
                                <a class="btn btn-primary btn-xs examine" data-account_name='{{ $item->name }}' data-account_id='{{$item->id}}'><i class="fa fa-gavel"></i> 重置密码</a>
                            @endcan

                            @can('personnel_del')
                                <a class="btn btn-primary btn-xs examine1" data-account_id='{{$item->id}}'><i class="fa fa-trash-o"></i> 删除</a>
                            @endcan
                        </td>
                        <td>
                            <input type="text" class="col-xs-5 change-sort" data-id="{{ $item->id }}" value="{{ $item->sort }}" />
                        </td>
                    </tr>
                @endforeach
                </tbody>
            </table>
            {{ $data->links() }}
        </div>
        <div class="modal fade loading custom-hide" id="hideFormSystem" tabindex="-1" role="dialog"
             aria-labelledby="hideFormLibelSystem" aria-hidden="true" data-backdrop="static" data-keyboard="false">
            <div class="modal-dialog">
                <div class="invoice" style="text-align: center">
                    <form class='form' action="{{ route('admin.personnel.resetpwd') }}" method="POST">
                        <input type="hidden" name="_token" value="{{ csrf_token() }}"/>
                        <input type="hidden" name="account_id" id="account_id">
                        <div class="form-group">
                            是否确定要重置<b id='account_name' style="padding: 0 10px;">  </b>的密码
                        </div>
                        <div class="form-group">
                            <button type="submit" class="btn btn-success">确定</button>
                            <button type="button" class="btn" id="closeHideFormSystem">关闭</button>
                        </div>
                    </form>
                </div>
            </div>
        </div>

        
        <div class="modal fade loading custom-hide" id="hideFormSystem1" tabindex="-1" role="dialog"
             aria-labelledby="hideFormLibelSystem" aria-hidden="true" data-backdrop="static" data-keyboard="false">
            <div class="modal-dialog">
                <div class="invoice" style="text-align: center">
                    <form class='form' action="{{ route('admin.personnel.delete') }}" method="POST">
                        <input type="hidden" name="_token" value="{{ csrf_token() }}"/>
                        <input type="hidden" name="user_id" id="user_id">
                        <div class="form-group">
                            是否确定要删除该工作人员？
                        </div>
                        <div class="form-group">
                            <button type="submit" class="btn btn-success">确定</button>
                            <button type="button" class="btn" id="closeHideFormSystem1">关闭</button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
@endsection
@push('scripts')
<script>
    $('.examine').on('click', function () {
        $("#hideFormSystem form").attr('action', $(this).attr('data-url'));
        $("#account_id").val($(this).data('account_id'))
        $("#account_name").text($(this).data('account_name'))
        $("#hideFormSystem").modal('show');
    });
    $('#closeHideFormSystem').on('click', function () {
        $("#hideFormSystem").modal('hide');
    });

    $('.examine1').on('click', function () {
        $("#hideFormSystem1 form").attr('action', $(this).attr('data-url'));
        $("#user_id").val($(this).data('account_id'))
        $("#hideFormSystem1").modal('show');
    });
    $('#closeHideFormSystem1').on('click', function () {
        $("#hideFormSystem1").modal('hide');
    });

    $('.change-sort').on('change', function () {
        var sort = $(this).val();
        var id = $(this).attr('data-id');
        $.ajax({
            url: '{{ route('admin.personnel.sort') }}',
            type: "GET",
            dataType:'json',
            data: {
                id: id,
                sort: sort,
            },
            success: function (re) {
            }
        });
    });

</script>
@endpush